<?php

namespace Common\Controller;

use Common\Model\UserModel;
use Think\Controller;

class BaseController extends Controller {

    protected $user = null;

    /**
     * 公共基类：初始化验证用户是否登陆
     */
    protected function _initialize(){
        $tokenString = cookie('token');
        $token = $tokenString ? decodeSimpleJwt($tokenString) : ['uid' => 0];
        define('UID', $token['uid']);
        // 通过缓存获取用户未读消息数
        $this->user = UID ? UserModel::getUserById(UID) : null;
        $this->assign('user', $this->user);
        $this->assign('mcount', $this->user['msg']);
    }
}